{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7ff723c6-c9d7-4260-ab6b-5a276c4efbab",
   "metadata": {},
   "source": [
    "- https://github.com/langchain-ai/langgraph/blob/main/docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb\n",
    "    - 更侧重任务规划（tasks planning，及管理）与执行 (tool use/function calling, execute)；\n",
    "        -  multi-step plan, plan means steps, 而非单步；\n",
    "    - https://arxiv.org/abs/2305.04091\n",
    "    - https://github.com/yoheinakajima/babyagi\n",
    "    - vs. ReAct (you think one step at a time，缺乏 high level 的 plan)\n",
    "        - Explicit long term planning (which even really strong LLMs can struggle with)\n",
    "        - Ability to use smaller/weaker models for the execution step, only using larger/better models for the planning step\n",
    "            - heterogeneous\n",
    "    - Plan-And-Execute：each task is still executed in sequence,\n",
    "- LangGraph\n",
    "    - 全局共享的 state，相当于所有节点的 working memory\n",
    "    - 将每个 node 理解为 agent，langgraph 的 graph 实例相当于定义了 agents 的组织运转方式，非常方便地构建 multi-agents 系统；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6ec4dd2b-54f0-4034-9a5c-0ca4b710d225",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:08.558787Z",
     "iopub.status.busy": "2024-10-30T13:58:08.558224Z",
     "iopub.status.idle": "2024-10-30T13:58:08.588112Z",
     "shell.execute_reply": "2024-10-30T13:58:08.585297Z",
     "shell.execute_reply.started": "2024-10-30T13:58:08.558733Z"
    }
   },
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "assert load_dotenv()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c26af9de-de79-4b9d-ac77-19672bb8916e",
   "metadata": {},
   "source": [
    "### tools & execution agent"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f3aea53-9efc-4685-bd9e-6141bf1dd245",
   "metadata": {},
   "source": [
    "- create_react_agent:\n",
    "    - cycle \n",
    "    - two nodes\n",
    "        - agent (llm) 不再产生 tool call 的请求为止；\n",
    "            - `not isinstance(last_message, AIMessage) or not last_message.tool_calls:`\n",
    "        - tools:\n",
    "            - `ToolNode()`：function executed\n",
    "    - base messages\n",
    "        - HumanMessage (from user query/request)\n",
    "        - AIMessage (generated by `agent` node)\n",
    "            - `tool_calls`：构造要调用的函数及其入参；\n",
    "        - ToolMessage (generated by `tools` node)\n",
    "            - 函数执行的结果；\n",
    "        - AIMessage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9f9cc06f-52f4-43f3-a189-c86dd9803de2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:08.590083Z",
     "iopub.status.busy": "2024-10-30T13:58:08.589580Z",
     "iopub.status.idle": "2024-10-30T13:58:09.683994Z",
     "shell.execute_reply": "2024-10-30T13:58:09.682316Z",
     "shell.execute_reply.started": "2024-10-30T13:58:08.590033Z"
    }
   },
   "outputs": [],
   "source": [
    "from langchain_community.tools.tavily_search import TavilySearchResults\n",
    "\n",
    "tools = [TavilySearchResults(max_results=3)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2571a553-b1b6-4ac6-8194-f9883c01e08a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:09.684988Z",
     "iopub.status.busy": "2024-10-30T13:58:09.684719Z",
     "iopub.status.idle": "2024-10-30T13:58:11.357643Z",
     "shell.execute_reply": "2024-10-30T13:58:11.356378Z",
     "shell.execute_reply.started": "2024-10-30T13:58:09.684969Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m System Message \u001b[0m================================\n",
      "\n",
      "You are a helpful assistant.\n",
      "\n",
      "=============================\u001b[1m Messages Placeholder \u001b[0m=============================\n",
      "\n",
      "\u001b[33;1m\u001b[1;3m{messages}\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "from langchain import hub\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "from langgraph.prebuilt import create_react_agent\n",
    "\n",
    "# Get the prompt to use - you can modify this!\n",
    "# https://smith.langchain.com/hub/ih/ih-react-agent-executor\n",
    "prompt = hub.pull(\"ih/ih-react-agent-executor\")\n",
    "prompt.pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8b31b3dc-14a3-41f1-b20c-f2ff75e9d6dd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:11.358970Z",
     "iopub.status.busy": "2024-10-30T13:58:11.358763Z",
     "iopub.status.idle": "2024-10-30T13:58:11.380518Z",
     "shell.execute_reply": "2024-10-30T13:58:11.378947Z",
     "shell.execute_reply.started": "2024-10-30T13:58:11.358952Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatPromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: list<span style=\"font-weight: bold\">[</span>typing.Annotated<span style=\"font-weight: bold\">[</span>typing.Union<span style=\"font-weight: bold\">[</span>typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.ai.AIMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ai'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.human.HumanMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'human'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.chat.ChatMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'chat'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.system.SystemMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'system'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.function.FunctionMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'function'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.tool.ToolMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'tool'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.ai.AIMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'AIMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.human.HumanMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'HumanMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.chat.ChatMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ChatMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.system.SystemMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'SystemMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.function.FunctionMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'FunctionMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.tool.ToolMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ToolMessageChunk'</span><span style=\"font-weight: bold\">)]]</span>, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">FieldInfo</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">annotation</span>=<span style=\"color: #800080; text-decoration-color: #800080\">NoneType</span>, <span style=\"color: #808000; text-decoration-color: #808000\">required</span>=<span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span>, <span style=\"color: #808000; text-decoration-color: #808000\">discriminator</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Discriminator</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">discriminator</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">function</span><span style=\"color: #000000; text-decoration-color: #000000\"> _get_type at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x796e88d28a40</span><span style=\"font-weight: bold\">&gt;</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_type</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_message</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_context</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"font-weight: bold\">))]]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'lc_hub_owner'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'ih'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'lc_hub_repo'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'ih-react-agent-executor'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'lc_hub_commit_hash'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'2a7f3083c7d6d9e656c8bb77567347c248f45c109c38f9104a1167f7cf113b87'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">messages</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">SystemMessagePromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">template</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'You are a helpful assistant.'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">MessagesPlaceholder</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">variable_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mChatPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'messages'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'messages'\u001b[0m: list\u001b[1m[\u001b[0mtyping.Annotated\u001b[1m[\u001b[0mtyping.Union\u001b[1m[\u001b[0mtyping.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.ai.AIMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ai'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.human.HumanMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'human'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.chat.ChatMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'chat'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.system.SystemMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'system'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.function.FunctionMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'function'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.tool.ToolMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'tool'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.ai.AIMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'AIMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.human.HumanMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'HumanMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.chat.ChatMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ChatMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.system.SystemMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'SystemMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.function.FunctionMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'FunctionMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.tool.ToolMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ToolMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m\u001b[1m]\u001b[0m, \u001b[1;35mFieldInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[33mannotation\u001b[0m=\u001b[35mNoneType\u001b[0m, \u001b[33mrequired\u001b[0m=\u001b[3;92mTrue\u001b[0m, \u001b[33mdiscriminator\u001b[0m=\u001b[1;35mDiscriminator\u001b[0m\u001b[1m(\u001b[0m\u001b[33mdiscriminator\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95mfunction\u001b[0m\u001b[39m _get_type at \u001b[0m\u001b[1;36m0x796e88d28a40\u001b[0m\u001b[1m>\u001b[0m, \u001b[33mcustom_error_type\u001b[0m=\u001b[3;35mNone\u001b[0m, \u001b[33mcustom_error_message\u001b[0m=\u001b[3;35mNone\u001b[0m, \u001b[33mcustom_error_context\u001b[0m=\u001b[3;35mNone\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mmetadata\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'lc_hub_owner'\u001b[0m: \u001b[32m'ih'\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'lc_hub_repo'\u001b[0m: \u001b[32m'ih-react-agent-executor'\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'lc_hub_commit_hash'\u001b[0m: \u001b[32m'2a7f3083c7d6d9e656c8bb77567347c248f45c109c38f9104a1167f7cf113b87'\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mmessages\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mSystemMessagePromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mprompt\u001b[0m=\u001b[1;35mPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mtemplate\u001b[0m=\u001b[32m'You are a helpful assistant.'\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mMessagesPlaceholder\u001b[0m\u001b[1m(\u001b[0m\u001b[33mvariable_name\u001b[0m=\u001b[32m'messages'\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from rich.pretty import pprint\n",
    "pprint(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d173f95b-2d96-4050-81f9-02bd6c1af0cc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:11.381400Z",
     "iopub.status.busy": "2024-10-30T13:58:11.381189Z",
     "iopub.status.idle": "2024-10-30T13:58:11.561336Z",
     "shell.execute_reply": "2024-10-30T13:58:11.559750Z",
     "shell.execute_reply.started": "2024-10-30T13:58:11.381381Z"
    }
   },
   "outputs": [],
   "source": [
    "# Choose the LLM that will drive the agent\n",
    "llm = ChatOpenAI(model=\"gpt-4o-2024-08-06\")\n",
    "agent_executor = create_react_agent(llm, tools, state_modifier=prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "04be31ea-112c-4981-8b28-6138e2194408",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:11.565248Z",
     "iopub.status.busy": "2024-10-30T13:58:11.565003Z",
     "iopub.status.idle": "2024-10-30T13:58:11.969098Z",
     "shell.execute_reply": "2024-10-30T13:58:11.967815Z",
     "shell.execute_reply.started": "2024-10-30T13:58:11.565227Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU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SNwRv3HoQQCJGi2YeJVhVxXRNpgeXcrUtafyHrDLVzj7nXla87slH9aN/c8d3d1G43DT0WNenMli6WZqPq36kF6s/20NmJsjD8rSCFGJeEGjpXFxwNdpPXaNz2D9gIC+twvbmHNPzaJv4fstCikV5eJvRvvHF+9k+0nib0b7xxfvZPtLd8cybhq5R1LQo1FeXib0b7xxfvZPtJ4m9G+8cX72T7SfHMm4auUdS0KNRXl4m9G+8cX72T7S+s4O6NY7f2Cgd8T3vcP2F2yfHMm4auUdS0b1F1hLkLzKNGCS/ff7WrXAc8/GeuzR1HlOIA36lXtw40ENG0Zp7T2T5e3ymeRntI2j2sTD3loJJ3PVxJOwGzWyLEYLG4CuYMZQrY+EncsrRNjDj7p2HU/GV31xMu9qVZXT7uiLU+srq1CIi4aC0uY0Vp/UNgWMpg8bkZwOUS2qkcjwPc3cCdlukWVNdVE3pm0mpFvFXoz4J4T+HxfZTxV6M+CeE/h8X2VKUW7tGNxzzlbzvRbxV6M+CeE/h8X2U8VejPgnhP4fF9lSlE7Rjcc85LzvRbxV6M+CeE/h8X2U8VejPgnhP4fF9lSlE7Rjcc85LzvaPFaG05grLbOOwGMoWG78s1apHG9u/fsQNxut4iLVVXVXN6pumsREWAIiICIiAiIgIiICIiAiIgIiICIiD/2Q==",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import Image, display\n",
    "\n",
    "try:\n",
    "    display(Image(agent_executor.get_graph().draw_mermaid_png()))\n",
    "except Exception:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "879244cd-24b4-4524-b4d2-ba87d5cf3ff2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:11.970734Z",
     "iopub.status.busy": "2024-10-30T13:58:11.970362Z",
     "iopub.status.idle": "2024-10-30T13:58:15.118331Z",
     "shell.execute_reply": "2024-10-30T13:58:15.116859Z",
     "shell.execute_reply.started": "2024-10-30T13:58:11.970700Z"
    }
   },
   "outputs": [],
   "source": [
    "resp = agent_executor.invoke({\"messages\": [(\"user\", \"who is the winnner of the us open\")]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8cda8763-53de-425d-a0e4-83c9bbba668a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:15.120686Z",
     "iopub.status.busy": "2024-10-30T13:58:15.120024Z",
     "iopub.status.idle": "2024-10-30T13:58:15.146193Z",
     "shell.execute_reply": "2024-10-30T13:58:15.144383Z",
     "shell.execute_reply.started": "2024-10-30T13:58:15.120637Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">HumanMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'who is the winnner of the us open'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'60ea152f-a76a-4932-8db1-1df22585b664'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">AIMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'The term \"US Open\" could refer to either the US Open Tennis Championships or the US Open Golf Championship. Could you please specify which one you are referring to?'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'refusal'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'token_usage'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">95</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">129</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'cached_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'reasoning_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'model_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gpt-4o-2024-08-06'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'system_fingerprint'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'fp_90354628f2'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'finish_reason'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'stop'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'logprobs'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'run-439ffda6-4330-425b-95a0-c25d1c89e151-0'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">usage_metadata</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">95</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'output_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">129</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">}</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[32m'messages'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mHumanMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'who is the winnner of the us open'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'60ea152f-a76a-4932-8db1-1df22585b664'\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mAIMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The term \"US Open\" could refer to either the US Open Tennis Championships or the US Open Golf Championship. Could you please specify which one you are referring to?'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'refusal'\u001b[0m: \u001b[3;35mNone\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'token_usage'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1;36m34\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1;36m95\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m129\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'cached_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'reasoning_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'model_name'\u001b[0m: \u001b[32m'gpt-4o-2024-08-06'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'system_fingerprint'\u001b[0m: \u001b[32m'fp_90354628f2'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'run-439ffda6-4330-425b-95a0-c25d1c89e151-0'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33musage_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'input_tokens'\u001b[0m: \u001b[1;36m95\u001b[0m, \u001b[32m'output_tokens'\u001b[0m: \u001b[1;36m34\u001b[0m, \u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m129\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m}\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fc11dfba-2bdf-4214-b58e-b2916bd86fc0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:15.148966Z",
     "iopub.status.busy": "2024-10-30T13:58:15.148406Z",
     "iopub.status.idle": "2024-10-30T13:58:16.982977Z",
     "shell.execute_reply": "2024-10-30T13:58:16.981341Z",
     "shell.execute_reply.started": "2024-10-30T13:58:15.148919Z"
    }
   },
   "outputs": [],
   "source": [
    "from langchain_core.messages import HumanMessage\n",
    "resp = agent_executor.invoke({\"messages\": [\n",
    "    HumanMessage(\"who is the winnner of the us open\")\n",
    "]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "264d48aa-75fe-4df2-b686-794fab58f28c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:16.986686Z",
     "iopub.status.busy": "2024-10-30T13:58:16.985252Z",
     "iopub.status.idle": "2024-10-30T13:58:17.011584Z",
     "shell.execute_reply": "2024-10-30T13:58:17.009729Z",
     "shell.execute_reply.started": "2024-10-30T13:58:16.986625Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">HumanMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'who is the winnner of the us open'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'0c92c478-a8b2-4ce4-901a-1e4d55647f1e'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">AIMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">\"Could you specify which US Open you're referring to? There are multiple US Open tournaments, including those for tennis and golf. If you could clarify whether you mean the US Open in tennis, the US Open in golf, or any other specific event, that would be helpful.\"</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'refusal'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'token_usage'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">55</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">95</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">150</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'cached_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'reasoning_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'model_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gpt-4o-2024-08-06'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'system_fingerprint'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'fp_9e15ccd6a4'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'finish_reason'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'stop'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'logprobs'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'run-73adc204-4dd2-468f-ab14-98ca26bd733d-0'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">usage_metadata</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">95</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'output_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">55</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">150</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">}</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[32m'messages'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mHumanMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'who is the winnner of the us open'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'0c92c478-a8b2-4ce4-901a-1e4d55647f1e'\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mAIMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"Could\u001b[0m\u001b[32m you specify which US Open you're referring to? There are multiple US Open tournaments, including those for tennis and golf. If you could clarify whether you mean the US Open in tennis, the US Open in golf, or any other specific event, that would be helpful.\"\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'refusal'\u001b[0m: \u001b[3;35mNone\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'token_usage'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1;36m55\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1;36m95\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m150\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'cached_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'reasoning_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'model_name'\u001b[0m: \u001b[32m'gpt-4o-2024-08-06'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'system_fingerprint'\u001b[0m: \u001b[32m'fp_9e15ccd6a4'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'run-73adc204-4dd2-468f-ab14-98ca26bd733d-0'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33musage_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'input_tokens'\u001b[0m: \u001b[1;36m95\u001b[0m, \u001b[32m'output_tokens'\u001b[0m: \u001b[1;36m55\u001b[0m, \u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m150\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m}\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "41d8a6cf-6068-4312-9556-974f8f2d64ce",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:17.013956Z",
     "iopub.status.busy": "2024-10-30T13:58:17.013437Z",
     "iopub.status.idle": "2024-10-30T13:58:25.965509Z",
     "shell.execute_reply": "2024-10-30T13:58:25.963574Z",
     "shell.execute_reply.started": "2024-10-30T13:58:17.013912Z"
    }
   },
   "outputs": [],
   "source": [
    "from langchain_core.messages import HumanMessage\n",
    "resp = agent_executor.invoke({\"messages\": [\n",
    "    HumanMessage(\"2024年诺贝尔物理学奖颁给了谁\")\n",
    "]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b224c277-66ab-4ec8-9807-5202e0b33ade",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:25.968355Z",
     "iopub.status.busy": "2024-10-30T13:58:25.967800Z",
     "iopub.status.idle": "2024-10-30T13:58:26.055471Z",
     "shell.execute_reply": "2024-10-30T13:58:26.053857Z",
     "shell.execute_reply.started": "2024-10-30T13:58:25.968306Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">HumanMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'2024年诺贝尔物理学奖颁给了谁'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'3eedfdc9-9943-4516-93ea-fa43444a969a'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">AIMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">''</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'tool_calls'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'id'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'call_urc6DQHRmio86CZ2y9q5Qe0L'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'arguments'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'{\"query\":\"2024 Nobel Prize in Physics winner\"}'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'tavily_search_results_json'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'refusal'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'token_usage'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">24</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">124</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'cached_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'reasoning_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'model_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gpt-4o-2024-08-06'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'system_fingerprint'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'fp_90354628f2'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'finish_reason'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'tool_calls'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'logprobs'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'run-52fab91b-ce19-4363-b8c9-58cfd1b24235-0'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">tool_calls</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'tavily_search_results_json'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'args'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'query'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'2024 Nobel Prize in Physics winner'</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'id'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'call_urc6DQHRmio86CZ2y9q5Qe0L'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'tool_call'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">usage_metadata</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">100</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'output_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">24</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">124</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ToolMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'[{\"url\": \"https://www.cnn.com/2024/10/08/science/nobel-prize-physics-hopfield-hinton-machine-learning-intl/index.html\", \"content\": \"Nobel Prize in physics 2024 awarded for work on artificial intelligence to John Hopfield and Geoffrey Hinton | CNN CNN10 About CNN The 2024 Nobel Prize in physics has been awarded to John Hopfield and Geoffrey Hinton for their fundamental discoveries in machine learning, which paved the way for how artificial intelligence is used today. “Their work was fundamental in laying the cornerstones for what we experience today as artificial intelligence,” Mark Pearce, a member of the Nobel committee of physics, told CNN. Michael Moloney, chief executive of the American Institute of Physics, told CNN that the Nobel Prize winners’ work had transformed science, allowing machine learning systems to process huge amounts of data and allow scientists to spot patterns they would not otherwise be able to see.\"}, {\"url\": \"https://www.ap.org/news-highlights/spotlights/2024/pioneers-in-artificial-intelligence-win-the-nobel-prize-in-physics/\", \"content\": \"This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024. STOCKHOLM (AP) — Two pioneers of artificial intelligence — John Hopfield and Geoffrey Hinton — won the Nobel Prize in physics Tuesday for helping create the building blocks of machine learning that is revolutionizing the way we work and live but also creates new threats for humanity. This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024.\"}, {\"url\": \"https://www.nobelprize.org/prizes/physics/2024/press-release/\", \"content\": \"Press release: The Nobel Prize in Physics 2024 - NobelPrize.org Nobel Prizes &amp; laureates All Nobel Prizes All Nobel Prizes 2024 Physics prize About the prize The Nobel Prize in Physics 2024 The Royal Swedish Academy of Sciences has decided to award the Nobel Prize in Physics 2024 to This year’s two Nobel Laureates in Physics have used tools from physics to develop methods that are the foundation of today’s powerful machine learning. In physics we use artificial neural networks in a vast range of areas, such as developing new materials with specific properties,” says Ellen Moons, Chair of the Nobel Committee for Physics. Illustration: The Nobel Prize in Physics 2024 (pdf) &lt;https://www.nobelprize.org/prizes/physics/2024/press-release/&gt; About the Nobel Prize organisation The Nobel Prize\"}]'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">name</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'tavily_search_results_json'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'2ebcdd70-4116-478d-a2bb-dc33836ec6e2'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">tool_call_id</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'call_urc6DQHRmio86CZ2y9q5Qe0L'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">artifact</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'query'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'2024 Nobel Prize in Physics winner'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'follow_up_questions'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'answer'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'images'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[]</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'results'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Nobel Prize in physics 2024 awarded for work on artificial intelligence ...'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'url'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'https://www.cnn.com/2024/10/08/science/nobel-prize-physics-hopfield-hinton-machine-learning-intl/index.html'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'content'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Nobel Prize in physics 2024 awarded for work on artificial intelligence to John Hopfield and Geoffrey Hinton | CNN CNN10 About CNN The 2024 Nobel Prize in physics has been awarded to John Hopfield and Geoffrey Hinton for their fundamental discoveries in machine learning, which paved the way for how artificial intelligence is used today. “Their work was fundamental in laying the cornerstones for what we experience today as artificial intelligence,” Mark Pearce, a member of the Nobel committee of physics, told CNN. Michael Moloney, chief executive of the American Institute of Physics, told CNN that the Nobel Prize winners’ work had transformed science, allowing machine learning systems to process huge amounts of data and allow scientists to spot patterns they would not otherwise be able to see.'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'score'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.9997367</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'raw_content'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Pioneers in artificial intelligence win the Nobel Prize in physics'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'url'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'https://www.ap.org/news-highlights/spotlights/2024/pioneers-in-artificial-intelligence-win-the-nobel-prize-in-physics/'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'content'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024. STOCKHOLM (AP) — Two pioneers of artificial intelligence — John Hopfield and Geoffrey Hinton — won the Nobel Prize in physics Tuesday for helping create the building blocks of machine learning that is revolutionizing the way we work and live but also creates new threats for humanity. This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024.'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'score'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.99973255</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'raw_content'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Press release: The Nobel Prize in Physics 2024 - NobelPrize.org'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'url'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'https://www.nobelprize.org/prizes/physics/2024/press-release/'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'content'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Press release: The Nobel Prize in Physics 2024 - NobelPrize.org Nobel Prizes &amp; laureates All Nobel Prizes All Nobel Prizes 2024 Physics prize About the prize The Nobel Prize in Physics 2024 The Royal Swedish Academy of Sciences has decided to award the Nobel Prize in Physics 2024 to This year’s two Nobel Laureates in Physics have used tools from physics to develop methods that are the foundation of today’s powerful machine learning. In physics we use artificial neural networks in a vast range of areas, such as developing new materials with specific properties,” says Ellen Moons, Chair of the Nobel Committee for Physics. Illustration: The Nobel Prize in Physics 2024 (pdf) &lt;https://www.nobelprize.org/prizes/physics/2024/press-release/&gt; About the Nobel Prize organisation The Nobel Prize'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'score'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.9988305</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'raw_content'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'response_time'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4.14</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">AIMessage</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'2024年的诺贝尔物理学奖授予了John Hopfield和Geoffrey Hinton，以表彰他们在人工智能领域的基础性发现，这些发现为现代机器学习的应用奠定了基础。'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'refusal'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">response_metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'token_usage'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">50</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">721</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">771</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'cached_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens_details'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'reasoning_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'model_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gpt-4o-2024-08-06'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'system_fingerprint'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'fp_90354628f2'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'finish_reason'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'stop'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'logprobs'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'run-621c153b-2c8e-474b-a918-68d5ecbed4cc-0'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">usage_metadata</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">721</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'output_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">50</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">771</span><span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">}</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[32m'messages'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mHumanMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'2024年诺贝尔物理学奖颁给了谁'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'3eedfdc9-9943-4516-93ea-fa43444a969a'\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mAIMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m''\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'tool_calls'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'id'\u001b[0m: \u001b[32m'call_urc6DQHRmio86CZ2y9q5Qe0L'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'function'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[32m'arguments'\u001b[0m: \u001b[32m'\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"query\":\"2024 Nobel Prize in Physics winner\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[32m'name'\u001b[0m: \u001b[32m'tavily_search_results_json'\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'function'\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'refusal'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'token_usage'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1;36m24\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1;36m100\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m124\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'cached_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'reasoning_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'model_name'\u001b[0m: \u001b[32m'gpt-4o-2024-08-06'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'system_fingerprint'\u001b[0m: \u001b[32m'fp_90354628f2'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'finish_reason'\u001b[0m: \u001b[32m'tool_calls'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'run-52fab91b-ce19-4363-b8c9-58cfd1b24235-0'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'name'\u001b[0m: \u001b[32m'tavily_search_results_json'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'args'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'query'\u001b[0m: \u001b[32m'2024 Nobel Prize in Physics winner'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'id'\u001b[0m: \u001b[32m'call_urc6DQHRmio86CZ2y9q5Qe0L'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'tool_call'\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33musage_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'input_tokens'\u001b[0m: \u001b[1;36m100\u001b[0m, \u001b[32m'output_tokens'\u001b[0m: \u001b[1;36m24\u001b[0m, \u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m124\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mToolMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'\u001b[0m\u001b[32m[\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"url\": \"https://www.cnn.com/2024/10/08/science/nobel-prize-physics-hopfield-hinton-machine-learning-intl/index.html\", \"content\": \"Nobel Prize in physics 2024 awarded for work on artificial intelligence to John Hopfield and Geoffrey Hinton | CNN CNN10 About CNN The 2024 Nobel Prize in physics has been awarded to John Hopfield and Geoffrey Hinton for their fundamental discoveries in machine learning, which paved the way for how artificial intelligence is used today. “Their work was fundamental in laying the cornerstones for what we experience today as artificial intelligence,” Mark Pearce, a member of the Nobel committee of physics, told CNN. Michael Moloney, chief executive of the American Institute of Physics, told CNN that the Nobel Prize winners’ work had transformed science, allowing machine learning systems to process huge amounts of data and allow scientists to spot patterns they would not otherwise be able to see.\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m, \u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"url\": \"https://www.ap.org/news-highlights/spotlights/2024/pioneers-in-artificial-intelligence-win-the-nobel-prize-in-physics/\", \"content\": \"This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024. STOCKHOLM \u001b[0m\u001b[32m(\u001b[0m\u001b[32mAP\u001b[0m\u001b[32m)\u001b[0m\u001b[32m — Two pioneers of artificial intelligence — John Hopfield and Geoffrey Hinton — won the Nobel Prize in physics Tuesday for helping create the building blocks of machine learning that is revolutionizing the way we work and live but also creates new threats for humanity. This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024.\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m, \u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"url\": \"https://www.nobelprize.org/prizes/physics/2024/press-release/\", \"content\": \"Press release: The Nobel Prize in Physics 2024 - NobelPrize.org Nobel Prizes & laureates All Nobel Prizes All Nobel Prizes 2024 Physics prize About the prize The Nobel Prize in Physics 2024 The Royal Swedish Academy of Sciences has decided to award the Nobel Prize in Physics 2024 to This year’s two Nobel Laureates in Physics have used tools from physics to develop methods that are the foundation of today’s powerful machine learning. In physics we use artificial neural networks in a vast range of areas, such as developing new materials with specific properties,” says Ellen Moons, Chair of the Nobel Committee for Physics. Illustration: The Nobel Prize in Physics 2024 \u001b[0m\u001b[32m(\u001b[0m\u001b[32mpdf\u001b[0m\u001b[32m)\u001b[0m\u001b[32m \u001b[0m\u001b[32m<\u001b[0m\u001b[32mhttps:\u001b[0m\u001b[32m//www.nobelprize.org/prizes/physics/2024/press-release/> About the Nobel Prize organisation The Nobel Prize\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m]\u001b[0m\u001b[32m'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mname\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'tavily_search_results_json'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'2ebcdd70-4116-478d-a2bb-dc33836ec6e2'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mtool_call_id\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'call_urc6DQHRmio86CZ2y9q5Qe0L'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33martifact\u001b[0m\u001b[39m=\u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'query'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'2024 Nobel Prize in Physics winner'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'follow_up_questions'\u001b[0m\u001b[39m: \u001b[0m\u001b[3;35mNone\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'answer'\u001b[0m\u001b[39m: \u001b[0m\u001b[3;35mNone\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'images'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m[\u001b[0m\u001b[1;39m]\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'results'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'title'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Nobel Prize in physics 2024 awarded for work on artificial intelligence ...'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'url'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'https://www.cnn.com/2024/10/08/science/nobel-prize-physics-hopfield-hinton-machine-learning-intl/index.html'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'content'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Nobel Prize in physics 2024 awarded for work on artificial intelligence to John Hopfield and Geoffrey Hinton | CNN CNN10 About CNN The 2024 Nobel Prize in physics has been awarded to John Hopfield and Geoffrey Hinton for their fundamental discoveries in machine learning, which paved the way for how artificial intelligence is used today. “Their work was fundamental in laying the cornerstones for what we experience today as artificial intelligence,” Mark Pearce, a member of the Nobel committee of physics, told CNN. Michael Moloney, chief executive of the American Institute of Physics, told CNN that the Nobel Prize winners’ work had transformed science, allowing machine learning systems to process huge amounts of data and allow scientists to spot patterns they would not otherwise be able to see.'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'score'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;36m0.9997367\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'raw_content'\u001b[0m\u001b[39m: \u001b[0m\u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'title'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Pioneers in artificial intelligence win the Nobel Prize in physics'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'url'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'https://www.ap.org/news-highlights/spotlights/2024/pioneers-in-artificial-intelligence-win-the-nobel-prize-in-physics/'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'content'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024. STOCKHOLM \u001b[0m\u001b[32m(\u001b[0m\u001b[32mAP\u001b[0m\u001b[32m)\u001b[0m\u001b[32m — Two pioneers of artificial intelligence — John Hopfield and Geoffrey Hinton — won the Nobel Prize in physics Tuesday for helping create the building blocks of machine learning that is revolutionizing the way we work and live but also creates new threats for humanity. This photo combo shows the 2024 Nobel Prize winners in Physics, professor John Hopfield, left, of Princeton University, and professor Geoffrey Hinton, of the University of Toronto, Tuesday, Oct. 8, 2024.'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'score'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;36m0.99973255\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'raw_content'\u001b[0m\u001b[39m: \u001b[0m\u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'title'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Press release: The Nobel Prize in Physics 2024 - NobelPrize.org'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'url'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'https://www.nobelprize.org/prizes/physics/2024/press-release/'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'content'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Press release: The Nobel Prize in Physics 2024 - NobelPrize.org Nobel Prizes & laureates All Nobel Prizes All Nobel Prizes 2024 Physics prize About the prize The Nobel Prize in Physics 2024 The Royal Swedish Academy of Sciences has decided to award the Nobel Prize in Physics 2024 to This year’s two Nobel Laureates in Physics have used tools from physics to develop methods that are the foundation of today’s powerful machine learning. In physics we use artificial neural networks in a vast range of areas, such as developing new materials with specific properties,” says Ellen Moons, Chair of the Nobel Committee for Physics. Illustration: The Nobel Prize in Physics 2024 \u001b[0m\u001b[32m(\u001b[0m\u001b[32mpdf\u001b[0m\u001b[32m)\u001b[0m\u001b[32m <https://www.nobelprize.org/prizes/physics/2024/press-release/\u001b[0m\u001b[32m>\u001b[0m\u001b[32m About the Nobel Prize organisation The Nobel Prize'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'score'\u001b[0m: \u001b[1;36m0.9988305\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'raw_content'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'response_time'\u001b[0m: \u001b[1;36m4.14\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mAIMessage\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'2024年的诺贝尔物理学奖授予了John Hopfield和Geoffrey Hinton，以表彰他们在人工智能领域的基础性发现，这些发现为现代机器学习的应用奠定了基础。'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'refusal'\u001b[0m: \u001b[3;35mNone\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mresponse_metadata\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'token_usage'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1;36m50\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1;36m721\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m771\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'prompt_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'cached_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[32m'completion_tokens_details'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'reasoning_tokens'\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'model_name'\u001b[0m: \u001b[32m'gpt-4o-2024-08-06'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'system_fingerprint'\u001b[0m: \u001b[32m'fp_90354628f2'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mid\u001b[0m=\u001b[32m'run-621c153b-2c8e-474b-a918-68d5ecbed4cc-0'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33musage_metadata\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'input_tokens'\u001b[0m: \u001b[1;36m721\u001b[0m, \u001b[32m'output_tokens'\u001b[0m: \u001b[1;36m50\u001b[0m, \u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m771\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m}\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "15b023dd-6b3d-4cc3-b6f0-335b5946a2e1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T13:58:26.057914Z",
     "iopub.status.busy": "2024-10-30T13:58:26.057365Z",
     "iopub.status.idle": "2024-10-30T13:58:26.111466Z",
     "shell.execute_reply": "2024-10-30T13:58:26.109934Z",
     "shell.execute_reply.started": "2024-10-30T13:58:26.057867Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resp['messages'][-1].tool_calls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65c6f048-0d94-4447-a753-5e2a1c86b51d",
   "metadata": {},
   "source": [
    "### define the graph"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03e3f2e9-9769-414a-9b68-4e8d16a89339",
   "metadata": {},
   "source": [
    "#### Define the (global share) State"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0734029b-facc-452c-b72a-f47569d096f4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:09:34.065645Z",
     "iopub.status.busy": "2024-10-30T14:09:34.065288Z",
     "iopub.status.idle": "2024-10-30T14:09:34.073293Z",
     "shell.execute_reply": "2024-10-30T14:09:34.071535Z",
     "shell.execute_reply.started": "2024-10-30T14:09:34.065616Z"
    }
   },
   "outputs": [],
   "source": [
    "import operator\n",
    "from typing import Annotated, List, Tuple, TypedDict\n",
    "\n",
    "class PlanExecute(TypedDict):\n",
    "    query: str\n",
    "    plan: List[str]\n",
    "    past_steps: Annotated[List[Tuple], operator.add]\n",
    "    response: str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81d8f4b7-0309-43f9-85d5-26a9fe5ad022",
   "metadata": {},
   "source": [
    "#### planning steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9ad0bb4e-5ade-4a2f-9d73-dd4220d36ba4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:10:11.466554Z",
     "iopub.status.busy": "2024-10-30T14:10:11.465932Z",
     "iopub.status.idle": "2024-10-30T14:10:11.480032Z",
     "shell.execute_reply": "2024-10-30T14:10:11.478135Z",
     "shell.execute_reply.started": "2024-10-30T14:10:11.466502Z"
    }
   },
   "outputs": [],
   "source": [
    "from pydantic import BaseModel, Field\n",
    "\n",
    "\n",
    "class Plan(BaseModel):\n",
    "    \"\"\"Plan to follow in future\"\"\"\n",
    "\n",
    "    steps: List[str] = Field(\n",
    "        description=\"different steps to follow, should be in sorted order\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "43cba8f8-3f9c-4817-83b2-f9d4da754a9a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:11:51.439067Z",
     "iopub.status.busy": "2024-10-30T14:11:51.438670Z",
     "iopub.status.idle": "2024-10-30T14:11:51.447133Z",
     "shell.execute_reply": "2024-10-30T14:11:51.445416Z",
     "shell.execute_reply.started": "2024-10-30T14:11:51.439036Z"
    }
   },
   "outputs": [],
   "source": [
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "\n",
    "planner_prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\n",
    "            \"system\",\n",
    "            \"\"\"For the given objective, come up with a simple step by step plan. \\\n",
    "This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. \\\n",
    "The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\"\"\",\n",
    "        ),\n",
    "        (\"placeholder\", \"{messages}\"),\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "eb608d5a-8545-4233-8387-9221f4eb31b3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:11:57.428375Z",
     "iopub.status.busy": "2024-10-30T14:11:57.427785Z",
     "iopub.status.idle": "2024-10-30T14:11:57.460949Z",
     "shell.execute_reply": "2024-10-30T14:11:57.459454Z",
     "shell.execute_reply.started": "2024-10-30T14:11:57.428325Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatPromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">optional_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: list<span style=\"font-weight: bold\">[</span>typing.Annotated<span style=\"font-weight: bold\">[</span>typing.Union<span style=\"font-weight: bold\">[</span>typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.ai.AIMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ai'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.human.HumanMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'human'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.chat.ChatMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'chat'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.system.SystemMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'system'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.function.FunctionMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'function'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.tool.ToolMessage, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'tool'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.ai.AIMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'AIMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.human.HumanMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'HumanMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.chat.ChatMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ChatMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.system.SystemMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'SystemMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.function.FunctionMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'FunctionMessageChunk'</span><span style=\"font-weight: bold\">)]</span>, typing.Annotated<span style=\"font-weight: bold\">[</span>langchain_core.messages.tool.ToolMessageChunk, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Tag</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">tag</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'ToolMessageChunk'</span><span style=\"font-weight: bold\">)]]</span>, <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">FieldInfo</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">annotation</span>=<span style=\"color: #800080; text-decoration-color: #800080\">NoneType</span>, <span style=\"color: #808000; text-decoration-color: #808000\">required</span>=<span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span>, <span style=\"color: #808000; text-decoration-color: #808000\">discriminator</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Discriminator</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">discriminator</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">function</span><span style=\"color: #000000; text-decoration-color: #000000\"> _get_type at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x796e88d28a40</span><span style=\"font-weight: bold\">&gt;</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_type</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_message</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>, <span style=\"color: #808000; text-decoration-color: #808000\">custom_error_context</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span><span style=\"font-weight: bold\">))]]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>: <span style=\"font-weight: bold\">[]}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">messages</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">SystemMessagePromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">template</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">MessagesPlaceholder</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">variable_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'messages'</span>, <span style=\"color: #808000; text-decoration-color: #808000\">optional</span>=<span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mChatPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33moptional_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'messages'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'messages'\u001b[0m: list\u001b[1m[\u001b[0mtyping.Annotated\u001b[1m[\u001b[0mtyping.Union\u001b[1m[\u001b[0mtyping.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.ai.AIMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ai'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.human.HumanMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'human'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.chat.ChatMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'chat'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.system.SystemMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'system'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.function.FunctionMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'function'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.tool.ToolMessage, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'tool'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.ai.AIMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'AIMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.human.HumanMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'HumanMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.chat.ChatMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ChatMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.system.SystemMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'SystemMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.function.FunctionMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'FunctionMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m, typing.Annotated\u001b[1m[\u001b[0mlangchain_core.messages.tool.ToolMessageChunk, \u001b[1;35mTag\u001b[0m\u001b[1m(\u001b[0m\u001b[33mtag\u001b[0m=\u001b[32m'ToolMessageChunk'\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m\u001b[1m]\u001b[0m, \u001b[1;35mFieldInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[33mannotation\u001b[0m=\u001b[35mNoneType\u001b[0m, \u001b[33mrequired\u001b[0m=\u001b[3;92mTrue\u001b[0m, \u001b[33mdiscriminator\u001b[0m=\u001b[1;35mDiscriminator\u001b[0m\u001b[1m(\u001b[0m\u001b[33mdiscriminator\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95mfunction\u001b[0m\u001b[39m _get_type at \u001b[0m\u001b[1;36m0x796e88d28a40\u001b[0m\u001b[1m>\u001b[0m, \u001b[33mcustom_error_type\u001b[0m=\u001b[3;35mNone\u001b[0m, \u001b[33mcustom_error_message\u001b[0m=\u001b[3;35mNone\u001b[0m, \u001b[33mcustom_error_context\u001b[0m=\u001b[3;35mNone\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'messages'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mmessages\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mSystemMessagePromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mprompt\u001b[0m=\u001b[1;35mPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mtemplate\u001b[0m=\u001b[32m'For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.'\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mMessagesPlaceholder\u001b[0m\u001b[1m(\u001b[0m\u001b[33mvariable_name\u001b[0m=\u001b[32m'messages'\u001b[0m, \u001b[33moptional\u001b[0m=\u001b[3;92mTrue\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(planner_prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2795cba0-20b5-429b-a2c9-6efe065b43fe",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:16:47.046152Z",
     "iopub.status.busy": "2024-10-30T14:16:47.045562Z",
     "iopub.status.idle": "2024-10-30T14:16:47.054108Z",
     "shell.execute_reply": "2024-10-30T14:16:47.052609Z",
     "shell.execute_reply.started": "2024-10-30T14:16:47.046103Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\n"
     ]
    }
   ],
   "source": [
    "print(planner_prompt.messages[0].prompt.template)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "cacdfcd5-472e-464e-864f-61caab85c2ad",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:13:02.728240Z",
     "iopub.status.busy": "2024-10-30T14:13:02.727649Z",
     "iopub.status.idle": "2024-10-30T14:13:02.833411Z",
     "shell.execute_reply": "2024-10-30T14:13:02.832321Z",
     "shell.execute_reply.started": "2024-10-30T14:13:02.728190Z"
    }
   },
   "outputs": [],
   "source": [
    "planner = planner_prompt | ChatOpenAI(\n",
    "    model=\"gpt-4o-2024-08-06\", temperature=0\n",
    ").with_structured_output(Plan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "920a926a-a323-4105-9e8b-2051a874be14",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:13:04.099765Z",
     "iopub.status.busy": "2024-10-30T14:13:04.099377Z",
     "iopub.status.idle": "2024-10-30T14:13:05.445361Z",
     "shell.execute_reply": "2024-10-30T14:13:05.443527Z",
     "shell.execute_reply.started": "2024-10-30T14:13:04.099735Z"
    }
   },
   "outputs": [],
   "source": [
    "response = planner.invoke({\n",
    "    \"messages\": [\n",
    "        (\"user\", \"what is the hometown of the current Australia open winner?\")\n",
    "    ]\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f6fe49f5-9ef5-4516-b285-9a8078357e73",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:13:13.315742Z",
     "iopub.status.busy": "2024-10-30T14:13:13.315128Z",
     "iopub.status.idle": "2024-10-30T14:13:13.330407Z",
     "shell.execute_reply": "2024-10-30T14:13:13.328635Z",
     "shell.execute_reply.started": "2024-10-30T14:13:13.315692Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Plan</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">steps</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'Identify the current year.'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'Determine the winner of the Australian Open for the current year.'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'Research the hometown of the identified winner.'</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'Provide the hometown as the final answer.'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mPlan\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'Identify the current year.'\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'Determine the winner of the Australian Open for the current year.'\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'Research the hometown of the identified winner.'\u001b[0m,\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[32m'Provide the hometown as the final answer.'\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c216bd6-7915-40f4-b942-cc2fb3309960",
   "metadata": {},
   "source": [
    "#### Re-Plan Step"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b16cda6a-27ba-4e20-a843-3ab125b9f21c",
   "metadata": {},
   "source": [
    "- Now, let's create a step that re-does the plan based on the result of the previous step."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "cb7d8620-4af4-4e5a-836a-112d0b2e46e8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:14:39.514542Z",
     "iopub.status.busy": "2024-10-30T14:14:39.513954Z",
     "iopub.status.idle": "2024-10-30T14:14:39.529688Z",
     "shell.execute_reply": "2024-10-30T14:14:39.528051Z",
     "shell.execute_reply.started": "2024-10-30T14:14:39.514476Z"
    }
   },
   "outputs": [],
   "source": [
    "from typing import Union\n",
    "\n",
    "class Response(BaseModel):\n",
    "    \"\"\"Response to user.\"\"\"\n",
    "    response: str\n",
    "\n",
    "class Act(BaseModel):\n",
    "    \"\"\"Action to perform.\"\"\"\n",
    "    action: Union[Response, Plan] = Field(\n",
    "        description=\"Action to perform. If you want to respond to user, use Response. \"\n",
    "        \"If you need to further use tools to get the answer, use Plan.\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "71d937d4-99bd-4b8c-91bd-ec37158a635d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:26:37.454851Z",
     "iopub.status.busy": "2024-10-30T14:26:37.454227Z",
     "iopub.status.idle": "2024-10-30T14:26:37.464151Z",
     "shell.execute_reply": "2024-10-30T14:26:37.462204Z",
     "shell.execute_reply.started": "2024-10-30T14:26:37.454800Z"
    }
   },
   "outputs": [],
   "source": [
    "replanner_prompt = ChatPromptTemplate.from_template(\n",
    "    \"\"\"For the given objective, come up with a simple step by step plan. \\\n",
    "This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. \\\n",
    "The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\n",
    "\n",
    "Your objective was this:\n",
    "{query}\n",
    "\n",
    "Your original plan was this:\n",
    "{plan}\n",
    "\n",
    "You have currently done the follow steps:\n",
    "{past_steps}\n",
    "\n",
    "Update your plan accordingly. If no more steps are needed and you can return to the user, then respond with that. Otherwise, fill out the plan. Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.\"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "c660b687-630a-4dac-9579-c952e6e29693",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:26:43.795640Z",
     "iopub.status.busy": "2024-10-30T14:26:43.795035Z",
     "iopub.status.idle": "2024-10-30T14:26:43.844155Z",
     "shell.execute_reply": "2024-10-30T14:26:43.842181Z",
     "shell.execute_reply.started": "2024-10-30T14:26:43.795587Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatPromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'past_steps'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'plan'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'query'</span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">messages</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">HumanMessagePromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'past_steps'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'plan'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'query'</span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">partial_variables</span>=<span style=\"font-weight: bold\">{}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">template</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\\n\\nYour objective was this:\\n{query}\\n\\nYour original plan was this:\\n{plan}\\n\\nYou have currently done the follow steps:\\n{past_steps}\\n\\nUpdate your plan accordingly. If no more steps are needed and you can return to the user, then respond with that. Otherwise, fill out the plan. Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.'</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_kwargs</span>=<span style=\"font-weight: bold\">{}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mChatPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'past_steps'\u001b[0m, \u001b[32m'plan'\u001b[0m, \u001b[32m'query'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mmessages\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mHumanMessagePromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mprompt\u001b[0m=\u001b[1;35mPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'past_steps'\u001b[0m, \u001b[32m'plan'\u001b[0m, \u001b[32m'query'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mpartial_variables\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33mtemplate\u001b[0m=\u001b[32m'For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\\n\\nYour objective was this:\\n\u001b[0m\u001b[32m{\u001b[0m\u001b[32mquery\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\n\\nYour original plan was this:\\n\u001b[0m\u001b[32m{\u001b[0m\u001b[32mplan\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\n\\nYou have currently done the follow steps:\\n\u001b[0m\u001b[32m{\u001b[0m\u001b[32mpast_steps\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\n\\nUpdate your plan accordingly. If no more steps are needed and you can return to the user, then respond with that. Otherwise, fill out the plan. Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.'\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33madditional_kwargs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(replanner_prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "538e86ce-1028-41c7-999c-ddfc646c019a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:26:45.889459Z",
     "iopub.status.busy": "2024-10-30T14:26:45.888883Z",
     "iopub.status.idle": "2024-10-30T14:26:45.898239Z",
     "shell.execute_reply": "2024-10-30T14:26:45.896385Z",
     "shell.execute_reply.started": "2024-10-30T14:26:45.889409Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\n",
      "\n",
      "Your objective was this:\n",
      "{query}\n",
      "\n",
      "Your original plan was this:\n",
      "{plan}\n",
      "\n",
      "You have currently done the follow steps:\n",
      "{past_steps}\n",
      "\n",
      "Update your plan accordingly. If no more steps are needed and you can return to the user, then respond with that. Otherwise, fill out the plan. Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.\n"
     ]
    }
   ],
   "source": [
    "print(replanner_prompt.messages[0].prompt.template)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "06bfe8a9-1b3b-4d2c-9d47-574b1db149d7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:26:48.369410Z",
     "iopub.status.busy": "2024-10-30T14:26:48.368853Z",
     "iopub.status.idle": "2024-10-30T14:26:48.476021Z",
     "shell.execute_reply": "2024-10-30T14:26:48.474441Z",
     "shell.execute_reply.started": "2024-10-30T14:26:48.369362Z"
    }
   },
   "outputs": [],
   "source": [
    "replanner = replanner_prompt | ChatOpenAI(\n",
    "    model=\"gpt-4o-2024-08-06\", temperature=0\n",
    ").with_structured_output(Act)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10ba698f-a603-4688-87a7-fc20cdf03223",
   "metadata": {},
   "source": [
    "#### Create the Graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "51d52803-5eb0-4ed6-b8e8-988bf46a40ed",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:17:36.141783Z",
     "iopub.status.busy": "2024-10-30T14:17:36.141358Z",
     "iopub.status.idle": "2024-10-30T14:17:36.148635Z",
     "shell.execute_reply": "2024-10-30T14:17:36.146835Z",
     "shell.execute_reply.started": "2024-10-30T14:17:36.141749Z"
    }
   },
   "outputs": [],
   "source": [
    "from typing import Literal\n",
    "from langgraph.graph import END"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "fb247462-7d2e-4ae2-a67f-dd0df7f2af8e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:18:57.148896Z",
     "iopub.status.busy": "2024-10-30T14:18:57.148327Z",
     "iopub.status.idle": "2024-10-30T14:18:57.160203Z",
     "shell.execute_reply": "2024-10-30T14:18:57.158628Z",
     "shell.execute_reply.started": "2024-10-30T14:18:57.148846Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'query': str,\n",
       " 'plan': typing.List[str],\n",
       " 'past_steps': typing.List[typing.Tuple],\n",
       " 'response': str}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from typing import get_type_hints\n",
    "get_type_hints(PlanExecute)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "3f7c194e-c063-46d9-90dc-6c022b5e2b0b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:24:03.722034Z",
     "iopub.status.busy": "2024-10-30T14:24:03.721409Z",
     "iopub.status.idle": "2024-10-30T14:24:03.738104Z",
     "shell.execute_reply": "2024-10-30T14:24:03.736203Z",
     "shell.execute_reply.started": "2024-10-30T14:24:03.721983Z"
    }
   },
   "outputs": [],
   "source": [
    "async def plan_step(state: PlanExecute):\n",
    "    plan = await planner.ainvoke({\"messages\": [(\"user\", state[\"query\"])]})\n",
    "    return {\"plan\": plan.steps}\n",
    "    \n",
    "async def execute_step(state: PlanExecute):\n",
    "    plan = state[\"plan\"]\n",
    "    plan_str = \"\\n\".join(f\"{i+1}. {step}\" for i, step in enumerate(plan))\n",
    "    task = plan[0]\n",
    "    task_formatted = f\"\"\"For the following plan:\n",
    "{plan_str}\\n\\nYou are tasked with executing step {1}, {task}.\"\"\"\n",
    "    agent_response = await agent_executor.ainvoke(\n",
    "        {\"messages\": [(\"user\", task_formatted)]}\n",
    "    )\n",
    "    # 追加\n",
    "    return {\n",
    "        \"past_steps\": [(task, agent_response[\"messages\"][-1].content)],\n",
    "    }\n",
    "\n",
    "async def replan_step(state: PlanExecute):\n",
    "    # replanner => Act (Response, or, Plan) \n",
    "    output = await replanner.ainvoke(state)\n",
    "    if isinstance(output.action, Response):\n",
    "        return {\"response\": output.action.response}\n",
    "    else:\n",
    "        return {\"plan\": output.action.steps}\n",
    "\n",
    "def should_end(state: PlanExecute):\n",
    "    if \"response\" in state and state[\"response\"]:\n",
    "        return END\n",
    "    else:\n",
    "        return \"agent\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "e9c09ed7-fd5f-47e3-8dfd-8716e1e19371",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:27:05.582899Z",
     "iopub.status.busy": "2024-10-30T14:27:05.582444Z",
     "iopub.status.idle": "2024-10-30T14:27:05.595017Z",
     "shell.execute_reply": "2024-10-30T14:27:05.592978Z",
     "shell.execute_reply.started": "2024-10-30T14:27:05.582863Z"
    }
   },
   "outputs": [],
   "source": [
    "from langgraph.graph import StateGraph, START\n",
    "\n",
    "workflow = StateGraph(PlanExecute)\n",
    "\n",
    "# Add the plan node\n",
    "workflow.add_node(\"planner\", plan_step)\n",
    "\n",
    "# Add the execution step\n",
    "workflow.add_node(\"agent\", execute_step)\n",
    "\n",
    "# Add a replan node\n",
    "workflow.add_node(\"replan\", replan_step)\n",
    "\n",
    "workflow.add_edge(START, \"planner\")\n",
    "\n",
    "# From plan we go to agent\n",
    "workflow.add_edge(\"planner\", \"agent\")\n",
    "\n",
    "# From agent, we replan\n",
    "workflow.add_edge(\"agent\", \"replan\")\n",
    "\n",
    "workflow.add_conditional_edges(\n",
    "    \"replan\",\n",
    "    # Next, we pass in the function that will determine which node is called next.\n",
    "    should_end,\n",
    "    [\"agent\", END],\n",
    ")\n",
    "\n",
    "# Finally, we compile it!\n",
    "# This compiles it into a LangChain Runnable,\n",
    "# meaning you can use it as you would any other runnable\n",
    "app = workflow.compile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "c1812ebb-3190-48a9-b399-41f1c5367d30",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:27:06.617700Z",
     "iopub.status.busy": "2024-10-30T14:27:06.617129Z",
     "iopub.status.idle": "2024-10-30T14:27:07.075574Z",
     "shell.execute_reply": "2024-10-30T14:27:07.074137Z",
     "shell.execute_reply.started": "2024-10-30T14:27:06.617653Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYU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FVe5eZfJsX8Sb+lPcvMvk2L+JN/SmFPajiYLVFVe5eZfJsX8Sb+leQx3J7i009bWW6gpn8JJKESPm3fGGF2gaSNRrodNddEwojOuEYJuy0abOMa+j4fYC1K9FBQwWyhp6OlibBS08bYYom9DGNGjQP2ABe9c+1ri0tKq465mSeeRERVIEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAWfsVvNLkuTVBs5oBUzwOFcarlRXbsDG74j1/Jbum5pw13d7xrQLOY9bhSZTlVSLO+gNVUQPNc6o5QV27Tsbvhn/T3dNzTx7uvjQaNERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBZzHqNsGU5VMLTNQmeogca2ScvZW6U7BvMb8AN03CB0lpPjWjWdsFI6DJ8omNsnoxPPA4VclRyjKvSBg3mM/wCmG6bhHjLSfGg0SIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiLOZHtDx7FJuQuNxYyq017VgY6aYDTUEsYC4D9ZGisos67WrRs4mZ+XOZtGi507btjYPCG6OHxigk/8AtfnPvjfzF19Retz3fe+6ngnCW2yG/UOLWC5Xq5zGntttppayqmbG6QxxRsL3u3Wgudo1pOjQSfECV8+7NOzI2MZftLulosV8nkvF9rqaGlf2lWuFwfyLGAhphAhDdN0726O5LjwOq6TPtwxeqhkhmpLnLDI0sfG+3uc1zSNCCD0ghfJHY2bGMY2KbfcvzCqhrp7NE58eNRike98ccvF7n/E5jTyY+PVx+JPd977qeBhL+gCLnPPvjfzF19RenPvjfzF19Renu+991PAwl0ZFz2LbpjDz+U90oG/Kfb5SB9VpK2FiyS15PSGptVfBXwtO64wvBLD8Th0tP6joVRa3a3sYxtKJiPnBhKyREWsgREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQcx2r7Qai2T+4FomMFc+NstVVs/OgjcSA1nxPdoePwRoelzSORw08dO1wjYGBzi92nS5x4lxPjJPSTxKk19dJdb1e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NRq1wBaf1EAjxrxkrqaFu9JURMb8bngBXWKYvc84mjFsidHQOI37pKzSFrfHua/wDMd8Qbw+MhZVV8jTNdtVERw8ZThMtVsPtTqvJbrd9PyNJTigY/43vc2SQfuDIvrLtKrcdx+jxez09toWuEEI/OedXvceLnuPjcTqT/APSsl87v151q3qtIy6tzIREWigREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAXqqaWGshdDURMnhdwdHI0Oaf2goiZClfs+xaR287GrQ4/GaCI/8A9V483eKebNm9Qi/pRFdy9r254ynGTm7xTzZs3qEX9Kc3eKebNm9Qi/pRFPL2vbnjJjJzd4p5s2b1CL+lObvFPNmzeoRf0oicva9ueMmMvfS4TjtDI2SmsNsp3tOodFRxtIP7Q1XSIq6q6q+eqcUCIiwBERAREQEREH//2Q==",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import Image, display\n",
    "\n",
    "display(Image(app.get_graph(xray=True).draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "7e5a5f81-b725-43cd-95f2-6fffc6d7ed15",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-30T14:27:48.793965Z",
     "iopub.status.busy": "2024-10-30T14:27:48.793598Z",
     "iopub.status.idle": "2024-10-30T14:28:10.970679Z",
     "shell.execute_reply": "2024-10-30T14:28:10.968696Z",
     "shell.execute_reply.started": "2024-10-30T14:27:48.793935Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'plan': [\"Identify the winner of the men's 2024 Australian Open.\", \"Research the winner's personal background to find their hometown.\", 'Verify the information from a reliable source to ensure accuracy.', 'Conclude with the hometown of the winner.']}\n",
      "{'past_steps': [(\"Identify the winner of the men's 2024 Australian Open.\", \"The winner of the men's 2024 Australian Open is Jannik Sinner.\")]}\n",
      "{'plan': [\"Research Jannik Sinner's personal background to find his hometown.\", 'Verify the information from a reliable source to ensure accuracy.', 'Conclude with the hometown of Jannik Sinner.']}\n",
      "{'past_steps': [(\"Research Jannik Sinner's personal background to find his hometown.\", \"Jannik Sinner's hometown is Sexten, also known as Sesto Pusteria, located in the Dolomites region of northern Italy.\")]}\n",
      "{'response': \"The hometown of the men's 2024 Australian Open winner, Jannik Sinner, is Sexten, also known as Sesto Pusteria, located in the Dolomites region of northern Italy.\"}\n"
     ]
    }
   ],
   "source": [
    "config = {\"recursion_limit\": 50}\n",
    "inputs = {\"query\": \"what is the hometown of the mens 2024 Australia open winner?\"}\n",
    "async for event in app.astream(inputs, config=config):\n",
    "    for k, v in event.items():\n",
    "        if k != \"__end__\":\n",
    "            print(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f53f757b-7fd2-47a6-9b72-5118bdea033a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "agent",
   "language": "python",
   "name": "agent"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
